// page-deviceInfo/deviceInfo.js
// deviceList.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    changeIntoIdentification: '',//转入身份证号
    deviceList: [],
    hiddenmodalput: true,//可以通过hidden是否掩藏弹出框的属性，来指定那个弹出框
    thatIndex: 0,
    device: {},
    falx:true
  },
  addDdevice: function (e) {
    //返回上一页
    wx.navigateTo({
      url: '/page-wode/deviceInformation/deviceInformation'
    })
    wx.redirectTo({
      //或者去没完成的页面
      url: '/page-wode/deviceInformation/deviceInformation'
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var factoryNum = wx.getStorageSync('factoryNum');
    //查询此设备的外观照片表是否有提交过照片
    if (factoryNum != null && factoryNum != '') {
      //查询此设备的外观照片表是否有提交过照片
      wx.request({
        url: app.globalData.requestURL +'deviceInformationImg/TbDeviceInformationImg',
        method: 'POST',
        data: {
          bigShelfNum: factoryNum
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success: function (res1) {
          //如果没有
          if (res1.data.status == '0'){
            wx.showModal({
              title: '完善信息',
              content: '是否完善设备信息',
              success: function (res2) {
                if (res2.confirm) {
                  wx.redirectTo({
                    url: '/page-deviceInformationImg/home'
                  })
                } else if (res2.cancel) {
                  console.log('用户点击取消')
                }
              }
            })
          } else if (res1.data.status == '1'){
            wx.request({
              url: app.globalData.requestURL +'deviceImg/getDeviceImgByCondition',
              method: 'POST',
              data: {
                bigShelfNum: factoryNum
              },
              header: {
                'content-type': 'application/x-www-form-urlencoded'
              },
              success: function (res3) {
                //如果有
                if (res3.data.status == '0') {
                  wx.showModal({
                    title: '完善信息',
                    content: '是否完善设备信息',
                    success: function (res4) {
                      if (res4.confirm) {
                        wx.redirectTo({
                          url: '/page-deviceImg/home'
                        })
                      } else if (res4.cancel) {
                        console.log('用户点击取消')
                      }
                    }
                  })
                } else if (res3.data.status == '1'){
                  wx.request({
                    url: app.globalData.requestURL +'billOfDocumentImg/getBillOfDocumentByCondition',//等查询此设备的手续的接口,
                    method: 'POST',
                    data: {
                      bigShelfNum: factoryNum
                    },
                    header: {
                      'content-type': 'application/x-www-form-urlencoded'
                    },
                    success: function (res5) {
                      if (res5.data.status == '0') {
                        wx.showModal({
                          title: '完善信息',
                          content: '是否完善设备信息',
                          success: function (res6) {
                            if (res6.confirm) {
                              wx.redirectTo({
                                url: '/page-billOfDocumentImg/bodImg-home'
                              })
                            } else if (res6.cancel) {
                              console.log('用户点击取消')
                            }
                          }
                        })
                      }
                    }
                  })
                }
              }
            })
          }
        }
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    var factoryNum = wx.getStorageSync("factoryNum");
    wx.request({
      url: app.globalData.requestURL +'deviceInformation/deviceInfoPage',
      method: 'GET',
      data:{
        factoryNum: factoryNum
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      success: function (res) {
        var device = res.data.data.records;
        if (device != null && device.length > 0) { 
          for (var i = 0; i < device.length; i++) {
            if (device[i].machineryType == '1') {
              device[i].machineryType = "挖掘机"
            }
            if (device[i].machineryType == '2') {
              device[i].machineryType = "装载机"
            }
            if (device[i].machineryType == '3') {
              device[i].machineryType = "矿用自卸车"
            }
            if (device[i].machineryType == '4') {
              device[i].machineryType = "推土机"
            }
            if (device[i].machineryType == '5') {
              device[i].machineryType = "压路机"
            }
            if (device[i].machineryType == '6') {
              device[i].machineryType = "平地机"
            }
            if (device[i].machineryType == '7') {
              device[i].machineryType = "混凝土机械"
            }
            if (device[i].machineryType == '8') {
              res.data.data[i].machineryType = "桩工机械"
            }
            if (device[i].machineryType == '9') {
              device[i].machineryType == "凿岩机械"
            }
            if (device[i].maneuver == '0') { 
              device[i].maneuver == '轮式'
            }
            if (device[i].maneuver == '1') { 
              device[i].maneuver == '履带'
            }
            if (device[i].fuel == '0') { 
              device[i].fuel == '柴油'
            }
            if (device[i].fuel == '1') {
              device[i].fuel == '汽油'
            }
            if (device[i].fuel == '2') {
              device[i].fuel == '天然气'
            }
            if (device[i].state == '0') {
              device[i].state == '待审核'
            }
            if (device[i].state == '1') {
              device[i].state == '审核中'
            }
            if (device[i].state == '2') {
              device[i].state == '已审核'
            }
            if (device[i].state == '3') {
              device[i].state == '审核未通过'
            }
            if (device[i].state == '4') {
              device[i].state == '已完成'
            }
            if (device[i].productionType == '0') {
              device[i].productionType == '国产'
            }
            if (device[i].productionType == '1') {
              device[i].productionType == '合资'
            }
            if (device[i].productionType == '2') {
              device[i].productionType == '进口'
            }
          }
          that.setData({
            deviceList: res.data.data.records
          });
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})